package com.talkingdata.hadoop.guard;

import com.talkingdata.hadoop.guard.bean.FolderState;
import com.talkingdata.hadoop.guard.bean.XmlConfig;
import com.talkingdata.hadoop.guard.util.DataTime;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.*;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.yarn.conf.YarnConfiguration;

import java.io.IOException;
import java.util.ArrayList;

public class hdfsCon {

    public static void main(String[] args) throws IOException {
        dfsInit();
    }
    public static void dfsInit() throws IOException {
        Configuration dfsConfig = new Configuration();
        FileSystem myhdfs;
        String path = "conf/yhhadoop310001/";
        String coreFile = path + "core-site.xml";
        String hdfsFile = path + "hdfs-site.xml";
        dfsConfig.set("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem");
        dfsConfig.set("dfs.client.failover.proxy.provider.yhhadoop310001" , "org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider");
        dfsConfig.addResource(new Path(coreFile));
        dfsConfig.addResource(new Path(hdfsFile));
            String krb5File = path + "krb5.conf";
            System.setProperty("java.security.krb5.conf", krb5File);
            UserGroupInformation.setConfiguration(dfsConfig);
            String keytabFile = path + "hadoop.keytab";
            UserGroupInformation.loginUserFromKeytab("hadoop/bj-jd-dc-namenode-prod-0009.tendcloud.com@HADOOP.COM",keytabFile);
        myhdfs = FileSystem.get(dfsConfig);
        FsStatus fs = myhdfs.getStatus();
        long capacity = fs.getCapacity();
        System.out.println("capacity : " + capacity);
        /*FileStatus[] fileStatuses = myhdfs.listStatus(new Path("/user/metadata"));
        for (FileStatus dir : fileStatuses) {
            if (dir.isDirectory()) {
                String nameDir = "/user/metadata/" + dir.getPath().getName();
                System.out.println(nameDir);
            }
        }*/
    }
}
